#include <iostream>
using namespace std;

struct Student{
	int total;
	int number;
	int chinese;
	int math;
	int english;
};

int compare(Student student1, Student student2);
int partition(Student (&student)[301], int begin, int end);
void quickSort(Student (&student)[301],int begin, int end){
	if(begin >= end) return;
	int p = partition(student, begin, end);
	quickSort(student, begin, p-1);
	quickSort(student, p+1, end);
}

int partition(Student (&student)[301], int begin, int end){
	Student temp = student[begin];
	int i = begin;
	int j = end;
	while(j > i){
		while(j > i && compare(student[j],temp) < 0) j--;
		if(j > i) 
			student[i] = student[j];
		while(i < j && compare(student[i], temp) > 0) i++;
		if(j > i) 
			student[j] = student[i];
	}
	student[i] = temp;
	return i;
}

int compare(Student student1, Student student2){
	if(student1.total > student2.total) return 1;
	if(student1.total < student2.total) return -1;
	if(student1.chinese > student2.chinese) return 1;
	if(student1.chinese < student2.chinese) return -1;
	if(student1.number < student2.number) return 1;
	if(student1.number > student2.number) return -1;
}

int main(){
	int stuNum;
	cin >> stuNum;
	Student student[301];
	for(int i = 1; i <= stuNum; i++){
		student[i].number=i;
		cin >> student[i].chinese >> student[i].math >> student[i].english;
		student[i].total = student[i].chinese + student[i].math + student[i].english;
	}
	quickSort(student, 1, stuNum);
	for(int i = 1; i <= 5; i++){
		cout << student[i].number << ' ' << student[i].total << endl;
	}
}

